import axios from 'axios'
import {REQUEST_AUTH_IDENT} from '@/config/common-config.ts'
import {errorMessageTip} from '@/utils/tip-utils'
import {UPLOAD_CONTENT_TYPE} from "@/constants/common-constant.ts";

// 创建axios实例
const service_file = axios.create({
    timeout: 50000 // 请求超时时间
})

// request拦截器
service_file.interceptors.request.use(
    (config) => {
        config.headers[REQUEST_AUTH_IDENT] = localStorage.getItem(REQUEST_AUTH_IDENT)
        config.headers['Content-Type'] = UPLOAD_CONTENT_TYPE
        return config
    },
    (error) => {
        errorMessageTip(error)
    }
)

// response拦截器 响应
service_file.interceptors.response.use(
    (response) => {
        return response.data;
    },
    (error) => {
        errorMessageTip(error.message)
        return error
    }
)

export default service_file